<template>
	<Layout>
		<Form ref="form1" :model="form1" :label-width="120">
			<Row v-show="!switchFlag" class="query-form" style="padding-top: 15px">
				<Col span="8">
				<FormItem label="驾驶员姓名：" prop="driverName">
					<Input class="query-form-el" type="text" v-model="form1.driverName" clearable></Input>
				</FormItem>
				</Col>
				<Col span="8">
				<FormItem label="事故日期：" prop="accDate">
					<DatePicker class="query-form-el" v-model="form1.dateRange" format="yyyy-MM-dd"
						type="daterange" placement="bottom-end" placeholder="请选择查询时间段"
						@on-change="selectQueryDateRange"></DatePicker>
				</FormItem>
				</Col>
				<Col span="8">
				<Button @click="reset" class="ivu-btn-reset">重置</Button>
				<Button type="primary" class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
				</Col>
			</Row>
			<Row class="query-form">
				<Col span="24">
				<Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
				</Col>
			</Row>
		</Form>

		<Table ref='table' :loading="loading" size="small" :height="tableHeight" no-data-text="没有查询到相关数据!"
			@on-selection-change='getSelectRows' border :columns="columns1" :data="dataTable">
		</Table>
		<Row style="margin-right:10px;">
			<Col span="24">
			<Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange"
				@on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray" show-total show-sizer
				show-elevator />
			</Col>
		</Row>
		<Modal :title="add?'交通事故信息新增':'交通事故信息修改'" :transfer=false v-model="model1" :width=600>
			<Row>
				<Col span="24">
				<Form ref="form1datacopy" :model="form1datacopy" :rules="ruleCustom" label-position="top">
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="驾驶员姓名：" prop="driverId">
							<Input type="text" readonly v-model="form1datacopy.userName">
							<Button slot="append" @click="openSupplyModel" icon="ios-search"></Button>
							</Input>
							<Input type="text" v-show="false" v-model="form1datacopy.driverId"></Input>
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="车牌号：" prop="plateNumber">
							<Input type="text" readonly v-model="form1datacopy.plateNumber">
							<Button slot="append" @click="openCarInfo" icon="ios-search"></Button>
							</Input>
							<Input type="text" v-show="false" v-model="form1datacopy.carId"></Input>
						</FormItem>
						</Col>
						
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="事故日期：" prop="accDate">
							<DatePicker v-model="form1datacopy.accDate" type="date" placeholder="请输入"
								style="width: 100%"></DatePicker>
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="发生地点：" prop="accAddress">
							<Input type="text" v-model="form1datacopy.accAddress"></Input>
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="定损人：" prop="assessor">
							<Input type="text" v-model="form1datacopy.assessor"></Input>
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="保险金额(元)：">
							<InputNumber v-model="form1datacopy.insurance" :min="0" style="width: 100%;"></InputNumber>
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="车辆所属单位：" prop="belongOrgId">
							<cascaderDom class="query-form-el" style="padding-top: 4px;width: 100%;" ref="carOrg"
								@setOrgInfo="setOrgId" @setOrgName="setOrgName" :currentOrgId="form1datacopy.belongOrgId"
								:currentOrgName="form1datacopy.orgName" :orgTree="true" ></cascaderDom>
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="车辆所有人：" prop="useEmp">
							<Input type="text" v-model="form1datacopy.useEmp" ></Input>
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="车辆所在单位：" prop="workOrgId">
							<cascaderDom class="query-form-el" style="padding-top: 4px;width: 100%;" ref="workOrg"
								@setOrgInfo="setWorkOrgId" @setOrgName="setWorkOrgName"
								:currentOrgId="form1datacopy.workOrgId" :currentOrgName="form1datacopy.workOrgName"
								:orgTree="true" ></cascaderDom>
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="事故说明：" prop="accState">
							<Input type="textarea" :rows="1" v-model="form1datacopy.accState"></Input>
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="事故处理：" prop="accHandle">
							<Input type="textarea" :rows="1" v-model="form1datacopy.accHandle"></Input>
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="处理结果：" prop="handleResult">
							<Input type="textarea" :rows="1" v-model="form1datacopy.handleResult"></Input>
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="责任认定：" prop="affirm">
							<Input type="textarea" :rows="1" v-model="form1datacopy.affirm"></Input>
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="修理地点：">
							<Input type="textarea" :rows="1" v-model="form1datacopy.repairAddress"></Input>
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="照片位置：">
							<Input type="textarea" :rows="1" v-model="form1datacopy.picAddress"></Input>
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="备注：" prop="notes">
							<Input v-model="form1datacopy.notes" type="textarea" :rows="2" />
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="照片文件：">
							<div style="width: 100%">
								<Upload ref="upload" :before-upload="beforeUpload" :show-upload-list="true"
									:max-size="10240" multiple type="drag" :action="fileUrl">
									<div style="padding: 20px">
										<Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
										<p>点击将文件拖拽到这里上传</p>
										<span style="font-size:8px;color: #797a64">支持扩展名：.rar .zip .doc .docx
											.pdf...</span>
									</div>
								</Upload>
							</div>

							<div v-show="uploadList.length>0" v-for="item in uploadList" :key='item'>
								<a @click="downloadFile(form1datacopy.accId,item)">{{ item.fileName }}</a>
								<Button type="text" icon="md-trash" @click="remove1(item.id)"
									style="margin-left: 5px;margin-bottom: 3px" />
							</div>
						</FormItem>
						</Col>
					</Row>
				</Form>
				</Col>
			</Row>
			<div slot="footer">
				<Button type="primary" class='ivu-btn-save' :loading="buttonLoading" @click="submit('form1datacopy')">
					确定
				</Button>
				<Button type="primary" class='ivu-btn-cancel' @click="handleCancel">取消</Button>
			</div>
		</Modal>
		<Modal title="交通事故信息详情" :transfer=false v-model="model2" :width=800>
			<Row>
				<Col span="24">
				<Form :model="form1datacopy" :label-width="160">
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="驾驶员姓名：" prop="userName">
							<a @click.prevent="getCarDriver">{{form1datacopy.userName}}</a>
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="车牌号：" prop="plateNumber">
							<a @click.prevent="getCarInfo">{{form1datacopy.plateNumber}}</a>
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="11">
						<FormItem label="事故日期：" prop="accDate">
							{{form1datacopy.accDate}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="发生地点：" prop="accAddress">
							{{form1datacopy.accAddress}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg ">
						<Col span="11">
						<FormItem label="定损人：" prop="assessor">
							{{form1datacopy.assessor}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="保险金额(元)：" prop="insurance">
							{{form1datacopy.insurance}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="23">
						<FormItem label="车辆所属单位：" prop="orgName">
							{{form1datacopy.orgName}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="车辆所有人：" prop="useEmp">
							{{form1datacopy.useEmp}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="23">
						<FormItem label="车辆所在单位：" prop="workOrgName">
							{{form1datacopy.workOrgName}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="事故说明：" prop="accState">
							{{form1datacopy.accState}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="23">
						<FormItem label="事故处理：" prop="accHandle">
							{{form1datacopy.accHandle}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="处理结果：" prop="handleResult">
							{{form1datacopy.handleResult}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="23">
						<FormItem label="修理地点：" prop="repairAddress">
							{{form1datacopy.repairAddress}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="责任认定：" prop="affirm">
							{{form1datacopy.affirm}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="23">
						<FormItem label="照片位置：" prop="picAddress">
							{{form1datacopy.picAddress}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="照片文件：">
							<div v-show="uploadList.length>0" v-for="item in uploadList" :key='item'>
								<a @click="downloadFile(form1datacopy.accId,item)">{{ item.fileName }}</a>
							</div>
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="23">
							<FormItem label="备注：" prop="notes">
								{{form1datacopy.notes}}
							</FormItem>
						</Col>
					</Row>
				</Form>
				</Col>
			</Row>
			<div slot="footer">
				<Button class='ivu-btn-save' @click="onCancel">关闭</Button>
			</div>
		</Modal>
		<Modal title="驾驶员姓名" :transfer=false footer-hide v-model="accidentForSelect" :width=900>
			<accidentForSelect @getSelectData="getSelectData">
			</accidentForSelect>
		</Modal>
		<Modal title="驾驶员信息" :transfer=false v-model="showCarDriver" :width=800>
			<Row>
				<Col span="24">
				<Form :model="carDriver" :label-width="160">
					<Row type="flex" justify="space-around" class="code-row-bg ">
						<Col span="23">
						<FormItem label="所属部门：" prop="orgName">
							{{carDriver.orgName}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="11">
						<FormItem label="姓名：" prop="userName">
							{{carDriver.userName}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="性别：" prop="gender">
							{{carDriver.gender}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="民族：" prop="race">
							{{carDriver.race}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="身份证号：" prop="idCard">
							{{carDriver.idCard}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg  detail-background-clor">
						<Col span="11">
						<FormItem label="出生日期：" prop="birthDay">
							{{carDriver.birthDay}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="联系电话：" prop="cellPhone">
							{{carDriver.cellPhone}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="职务：" prop="position">
							{{carDriver.position}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="驾照号：" prop="driverNumber">
							{{carDriver.driverNumber}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg  detail-background-clor">
						<Col span="11">
						<FormItem label="入职日期：" prop="enrollDate">
							{{carDriver.enrollDate}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="初次领证日期：" prop="beginDate">
							{{carDriver.beginDate}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="有效期限(年)：" prop="timeLimit">
							{{carDriver.timeLimit}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="年审到期：" prop="deadline">
							{{carDriver.deadline}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg  detail-background-clor">
						<Col span="11">
						<FormItem label="准车车型：" prop="driverType">
							{{carDriver.driveType}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="驾龄(月)：" prop="driveYears">
							{{carDriver.driveYears}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="发证机关：" prop="department">
							{{carDriver.department}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="Email：" prop="email">
							{{carDriver.email}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="11">
						<FormItem label="学历：" prop="educationName">
							{{carDriver.educationName}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="院校：" prop="college">
							{{carDriver.college}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="籍贯：" prop="homePlace">
							{{carDriver.homePlace}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg  detail-background-clor">
						<Col span="23">
						<FormItem label="现住址：" prop="address">
							{{carDriver.address}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="备注：" prop="notes">
							{{carDriver.notes}}
						</FormItem>
						</Col>
					</Row>
				</Form>
				</Col>
			</Row>
			<div slot="footer">
				<Button class='ivu-btn-save' @click="showCarDriver=false">关闭</Button>
			</div>
		</Modal>
		
		<Modal title="车辆信息" :transfer=false footer-hide v-model="violationForSelect" :width=900>
			<violationForSelect @getSelectData="getSelectCarInfo"></violationForSelect>
		</Modal>
		<Modal title="车辆详情" :transfer=false v-model="showCarInfo" :width=800>
			<Row>
				<Col span="24">
				<Form :model="carInfo" :label-width="160">
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="车辆名称：" prop="carName">
							{{carInfo.carName}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="车辆编号：" prop="serialNumber">
							{{carInfo.serialNumber}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="11">
						<FormItem label="车牌号：" prop="plateNumber">
							{{carInfo.plateNumber}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="车辆类型：" prop="carTypeName">
							{{carInfo.carTypeName}}
						</FormItem>
						</Col>
			
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="当前状态：" prop="carStatusName">
							{{carInfo.carStatusName}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="车辆性质：" prop="carPropertyName">
							{{carInfo.carPropertyName}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="11">
						<FormItem label="车辆型号：" prop="carModel">
							{{carInfo.carModel}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="燃油类别：" prop="gasTypeName">
							{{carInfo.gasTypeName}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="购买日期：" prop="purchaseDate">
							{{carInfo.purchaseDate}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="年检日期：" prop="inspectDate">
							{{carInfo.inspectDate}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="23">
						<FormItem label="所属单位：" prop="orgName">
							{{carInfo.orgName}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="23">
						<FormItem label="所有人：" prop="userName">
							{{carInfo.userName}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="23">
						<FormItem label="所在单位：" prop="workOrgName">
							{{carInfo.workOrgName}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="发动机编号：" prop="engineSeq">
							{{carInfo.engineSeq}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="车架号：" prop="bodyNumber">
							{{carInfo.bodyNumber}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="23">
						<FormItem label="生产厂家：" prop="carFactory">
							{{carInfo.carFactory}}
						</FormItem>
						</Col>
			
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="自重(KG)：" prop="carWeight" style="width: 100%;">
							{{carInfo.carWeight}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="车长(CM)：" prop="carLen" style="width: 100%;">
							{{carInfo.carLen}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="11">
						<FormItem label="车宽(CM)：" prop="carWidth" style="width: 100%;">
							{{carInfo.carWidth}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="车高(CM)：" prop="carHeight" style="width: 100%;">
							{{carInfo.carHeight}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg">
						<Col span="11">
						<FormItem label="车身颜色：" prop="carColor">
							{{carInfo.carColor}}
						</FormItem>
						</Col>
						<Col span="11">
						<FormItem label="厂牌：" prop="carFactoryNumber">
							{{carInfo.carFactoryNumber}}
						</FormItem>
						</Col>
					</Row>
					<Row type="flex" justify="space-around" class="code-row-bg detail-background-clor">
						<Col span="23">
						<FormItem label="备注：" prop="notes">
							{{carInfo.notes}}
						</FormItem>
						</Col>
					</Row>
				</Form>
				</Col>
			</Row>
			<div slot="footer">
				<Button class='ivu-btn-save' @click="showCarInfo=false">关闭</Button>
			</div>
		</Modal>
	</Layout>
</template>

<script>
	import {
		Api
	} from '../../../../api/index.js'
	import accidentForSelect from './accidentForSelect.vue'
	import violationForSelect from '../violation/violationForSelect.vue'
	import cascaderDom from "../../../../components/cascader-dom.vue"
	import {
		sessionStorage
	} from '../../../../common/cacheUtils.js';

	export default {
		name: "accident",
		components: {
			accidentForSelect,
			violationForSelect,
			cascaderDom
		},
		data() {
			return {
				currentUser: JSON.parse(sessionStorage('userId').get('userId')),
				uploadList: [],
				carDriver: {},
				showCarDriver: false,
				file: null,
				fileName: null,
				switchFlag: false,
				form1: {},
				pageSizeArray: [10, 20, 50],
				pagedata: {
					total: 0,
					pageSize: 10,
					currentPage: 1,
				},
				dataTable: [],
				columns1: [{
						title: "序号",
						width: 80,
						align: "center",
						fixed: 'left',
						render: (h, params) => {
							return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata
								.pageSize + 1);
						}
					},
					{
						title: '驾驶员姓名',
						minWidth: 150,
						align: 'center',
						fixed: 'left',
						key: 'userName',
					},
					{
						title: '事故日期',
						minWidth: 150,
						align: 'center',
						key: 'accDate',
						render: (h, params) => {
							return h('div', [
								(this.formatDate(new Date(params.row.accDate), 'yyyy-MM-dd'))
							]);
						}
					},
					{
						title: '发生地点',
						minWidth: 150,
						align: 'center',
						tooltip: true,
						key: 'accAddress',
					},
					{
						title: '事故说明',
						minWidth: 150,
						align: 'center',
						tooltip: true,
						key: 'accState',
					},
					{
						title: '事故处理',
						minWidth: 150,
						align: 'center',
						tooltip: true,
						key: 'accHandle',
					},
					{
						title: '车辆性质',
						minWidth: 150,
						align: 'center',
						key: 'handleResult',
					},
					{
						title: '修理地点',
						minWidth: 150,
						align: 'center',
						tooltip: true,
						key: 'repairAddress',
					},
					{
						title: '保险金额(元)',
						minWidth: 150,
						align: 'center',
						key: 'insurance',
					},
					{
						title: '责任认定',
						minWidth: 150,
						align: 'center',
						tooltip: true,
						key: 'affirm',
					},
					{
						title: '定损人',
						minWidth: 150,
						align: 'center',
						key: 'assessor',
					},
					{
						title: '操作',
						key: 'action',
						fixed: 'right',
						width: 200,
						align: 'center',
						render: (h, params) => {
							let currentUser=JSON.parse(sessionStorage('userId').get('userId'));
							if(currentUser.loginId === this.Common.admin || currentUser.userId === params.row.createUserId  || currentUser.userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined
									||sessionStorage('userId').getObject('userId').userBeHandedOver.find(obj => obj == params.row.createUserId) != undefined){
								return h('div', [
									h('A', {
										props: {
											type: 'primary',
											size: 'small'
										},
										style: {
											fontSize: '14px',
										},
										on: {
											click: () => {
												this.showData(params, 1);
											}
										}
									}, '详情'),
									h('Divider', {
										props: {
											type: 'vertical',
										}
									}, ''),
									h('A', {
										props: {
											type: 'primary',
											size: 'small'
										},
										style: {
											fontSize: '14px',
										},
										on: {
											click: () => {
												this.showData(params, 2);
											}
										}
									}, '修改'),
									h('Divider', {
										props: {
											type: 'vertical',
										}
									}, ''),
									h('A', {
										props: {
											type: 'error',
											size: 'small'
										},
										style: {
											fontSize: '14px',
											color: 'red',
										},
										on: {
											click: () => {
												this.$Modal.confirm({
													title: '提示',
													content: '<p>是否要删除？</p>',
													onOk: () => {
														this.deleteData(params);
													},
													onCancel: () => {}
												});
											}
										}
									}, '删除')
								]);
							}else{
								return h('div', [
								    h('A', {
								        props: {
								            type: 'primary',
								            size: 'small'
								        },
								        style: {
								            fontSize: '14px',
								        },
								        on: {
								            click: () => {
								                this.showData(params, 1);
								            }
								        }
								    }, '详情'),
								    h('Divider', {
								        props: {
								            type: 'vertical',
								        }
								    }, ''),
								    h('A', {
								        props: {
								            type: 'primary',
								            size: 'small'
								        },
								        style: {
								            fontSize: '14px',
											color: '#c5c8ce'
								        },
								    }, '修改'),
								    h('Divider', {
								        props: {
								            type: 'vertical',
								        }
								    }, ''),
								    h('A', {
								        props: {
								            type: 'primary',
								            size: 'small'
								        },
								        style: {
								            fontSize: '14px',
								            color: '#c5c8ce'
								        }
								    }, '删除')
								]);
							}
						}
					},

				],
				ruleCustom: {
					accDate: [{
						validator: (rule, value, callback) => {
							if (value == null || value == '' || value == undefined) {
								callback(' ')
							} else {
								callback()
							}
						},
						required: true,
						trigger: 'change'
					}],
					driverId: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					accAddress: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					accState: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					accHandle: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					handleResult: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					repairAddress: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					insurance: [{
						required: true,
						message: '  ',
						trigger: 'blur',
						type: "number"
					}],

					affirm: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					assessor: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					belongOrgId: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					workOrgId: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
					useEmp: [{
						required: true,
						message: '  ',
						trigger: 'blur'
					}],
				},
				fileUrl: Api.interestedPartiesUserFile,
				add: false,
				model1: false,
				buttonLoading: false,
				model2: false,
				showdata: {},
				form1datacopy: {},
				loading: false,
				tableHeight: 10,
				accidentForSelect: false,
				violationForSelect: false,
				showCarInfo: false,
				carInfo: {},
			}
		},
		mounted() {
			this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
			this.query();
		},
		methods: {
			selectQueryDateRange(data) {
			    if (data[0] === "" || data[1] === "") {
			        this.form1.beginDate = null;
			        this.form1.endDate = null;
			    } else {
			        this.form1.beginDate = data[0] + ' 00:00:00';
			        this.form1.endDate = data[1] + ' 23:59:59';
			    }
			},
			setOrgId(data) {
				this.form1datacopy.belongOrgId = data[data.length - 1];
			},
			setOrgName(data) {
				this.form1datacopy.orgName = data;
			},
			
			setWorkOrgId(data) {
				this.form1datacopy.workOrgId = data[data.length - 1];
			},
			setWorkOrgName(data) {
				this.form1datacopy.workOrgName = data;
			},
			getCarInfo() {
				this.carInfo.purchaseDate = this.formatDate(new Date(this.carInfo.purchaseDate), 'yyyy-MM-dd');
				this.carInfo.inspectDate = this.formatDate(new Date(this.carInfo.inspectDate), 'yyyy-MM-dd');
				this.showCarInfo = true;
			},
			openCarInfo(row) {
				this.violationForSelect = true;
			},
			getCarDriver() {
				this.carDriver.birthDay = this.formatDate(new Date(this.carDriver.birthDay), 'yyyy-MM-dd');
				this.carDriver.enrollDate = this.formatDate(new Date(this.carDriver.enrollDate), 'yyyy-MM-dd');
				this.carDriver.beginDate = this.formatDate(new Date(this.carDriver.beginDate), 'yyyy-MM-dd');
				this.carDriver.deadline = this.formatDate(new Date(this.carDriver.deadline), 'yyyy-MM-dd');
				this.showCarDriver = true;
			},
			getSelectData(row) {
				this.form1datacopy.driverId = row.userId;
				this.form1datacopy.userName = row.userName;
				this.accidentForSelect = false;
			},
			getSelectCarInfo(row) {
				this.form1datacopy.carId=row.eqId;
				this.form1datacopy.plateNumber=row.plateNumber;
				this.form1datacopy.belongOrgId=row.belongOrgId;
				this.form1datacopy.orgName=row.orgName;
				this.form1datacopy.workOrgId=row.workOrgId;
				this.form1datacopy.workOrgName=row.workOrgName;
				this.form1datacopy.useEmp=row.userName;
				setTimeout(() => {
					this.$refs.carOrg.setCurrentOrg();
					this.$refs.workOrg.setCurrentOrg();
				}, 100)
				this.violationForSelect = false;
			},
			openSupplyModel() {
				this.accidentForSelect = true;
			},


			deleteData(params) {
				let url = Api.deleteEqTrafficAccident;
				this.$http.delete(url + '/' + params.row.accId, {
					params: {}
				}).then((res) => {
					this.$Message.success('成功');
					this.query()
				}).catch(e => {
					this.$Message.error('请求失败' + e);
				})
			},
			setOrgId(data) {
				this.form1datacopy.belongOrgId = data[data.length - 1];
			},
			setOrgName(data) {
				this.form1datacopy.orgName = data;
			},
			getSelectRows(rows) {
				this.deleteRows = rows;
			},
			addInfo() {
				this.uploadList = [];
				this.form1datacopy = {
					accId: this.get_uuid(),
					insurance: 0
				};
				this.currentOrgId = '';
				this.currentOrgName = '';
				this.model1 = true;
				this.add = true;
			},
			get_uuid() {
				let s = [];
				let hexDigits = "0123456789abcdef";
				for (let i = 0; i < 36; i++) {
					s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
				}
				s[14] = "4";
				s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
				s[8] = s[13] = s[18] = s[23] = "-";

				let uuid = s.join("");
				let reg = new RegExp("-", "g");
				let a = uuid.replace(reg, "");
				return a;
			},
			pageChange(pageNum) {
				this.pagedata.currentPage = pageNum;
				this.query();
			},
			pageSizeChange(pageSize) {
				this.pagedata.pageSize = pageSize;
				this.query();
			},
			handleCancel() {
				this.form1datacopy = {
					carLen: 0,
					carWeight: 0,
					carHeight: 0,
					carWidth: 0,
				};
				this.model1 = false;
			},
			onCancel() {
				this.model2 = false;
			},
			switchQuery(flag) {
				this.switchFlag = flag;
				if (!this.switchFlag) {
					this.tableHeight = window.innerHeight - 220;
				} else {
					this.tableHeight = window.innerHeight - 315;
				}
			},
			reset() {
				this.form1 = {}
				this.query()
			},
			downloadFile(perfId, file) {
				let url = this.fileUrl + '/file/' + file.id;
				this.$http.get(url, {
					responseType: 'blob' //告诉服务器我们需要的响应格式
				}).then((res) => {
					const aLink = document.createElement("a");
					let blob = new Blob([res.data], {
						type: res.bodyBlob.type //将会被放入到blob中的数组内容的MIME类型
					});
					aLink.href = URL.createObjectURL(blob)
					aLink.download = file.fileName //标题
					aLink.click()
					document.body.appendChild(aLink)
				})
			},
			remove1(id) {
				let url = this.fileUrl + '/file/' + id;
				this.$http.delete(url).then((res) => {
					this.getFiles()
				})
			},
			beforeUpload(file) {
				let formData = new FormData();
				formData.append("files", file); // 文件对象
				let url = this.fileUrl + '/' + this.form1datacopy.accId + '/files/accidentFile'
				this.$http.post(url, formData).then((res) => {
					if (res.data.result == "success") {
						this.$Message.info("文件上传成功")
						this.getFiles();
					}
				})
				return false
			},
			getFiles() {
				let url = this.fileUrl + '/' + this.form1datacopy.accId + '/files/accidentFile'
				this.$http.get(url).then((res) => {
					if (res.data.result == "success") {
						this.uploadList = res.data.data
					}
				})
			},
			query() {
				this.loading = true;
				this.form1.orgId = sessionStorage('userId').getObject('userId').companyId;
				let data = {
				    startPage: this.pagedata.currentPage,
				    size: this.pagedata.pageSize,
				    conditions: this.form1
				};
				this.$http.post(Api.queryEqTrafficAccident,data).then((res) => {
					if (res.data.status === 201) {
					    this.$Message.error(res.data.msg);
						this.loading = false;
					}
					this.dataTable = res.data.data.data;
					this.pagedata.total = res.data.data.totalSize;
					this.loading = false;
				}).catch(e => {
					this.$Message.error("数据获取失败")
				})
			},
			showData(data, flag) {
				if (flag == 1) {
					//查看页面
					this.form1datacopy = data.row;
					this.getFiles();
					let url = Api.getEqCarDriver + "/" + this.form1datacopy.driverId;
					this.$http.get(url).then((res) => {
						this.carDriver = res.data.data;
					}).catch(e => {
						this.$Message.error("数据获取失败")
					})
					setTimeout(() => {
						this.form1datacopy.accDate = this.formatDate(new Date(this.form1datacopy.accDate), 'yyyy-MM-dd');
					}, 100)
					this.model2 = true;
					this.$http.get(Api.getEqCarInfo + "/" + this.form1datacopy.carId).then((res) => {
						if (res.data.status === 200) {
							this.carInfo = res.data.data;
						} else if (res.data.status === 201) {
							this.$Message.error(res.data.msg);
						}
					}).catch(e => {
						this.model1 = false;
						this.query();
						this.$Message.error("数据获取失败")
					})
				} else {
					//修改页面
					this.add = false;
					this.form1datacopy = JSON.parse(JSON.stringify(data.row));
					this.getFiles();
					this.model1 = true;
				}
			},
			formatDate(date, fmt) {
				if (/(y+)/.test(fmt)) {
					fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
				}
				let o = {
					'M+': date.getMonth() + 1,
					'd+': date.getDate(),
					'h+': date.getHours(),
					'm+': date.getMinutes(),
					's+': date.getSeconds()
				};
				for (let k in o) {
					if (new RegExp(`(${k})`).test(fmt)) {
						let str = o[k] + '';
						fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
					}
				}
				return fmt;
			},
			submit(name) {
				this.$refs[name].validate((valid) => {
					if (valid) {
						this.buttonLoading = true
						this.form1datacopy.accDate = this.formatDate(new Date(this.form1datacopy.accDate),
							'yyyy-MM-dd');
						let userId = sessionStorage('userId').getObject('userId').userId;
						let orgId = sessionStorage('userId').getObject('userId').orgInfo.orgId;
						if (this.add) {
							this.form1datacopy.createUserId = userId;
							this.form1datacopy.createOrgId = orgId;
							this.$http.post(Api.addEqTrafficAccident, this.form1datacopy).then((res) => {
								this.$Message.success("保存成功")
								this.model1 = false;
								this.query();
								this.buttonLoading = false
							}).catch(e => {
								this.model1 = false;
								this.query();
								this.buttonLoading = false
								this.$Message.error("数据获取失败")
							})
						} else {
							this.form1datacopy.updateUserId = userId;
							this.form1datacopy.updateOrgId = orgId;
							this.$http.post(Api.updateEqTrafficAccident, this.form1datacopy).then((res) => {
								this.$Message.success("保存成功")
								this.model1 = false;
								this.query();
								this.buttonLoading = false
							}).catch(e => {
								this.model1 = false;
								this.query();
								this.buttonLoading = false
								this.$Message.error("数据获取失败")
							})
						}
					} else {
						this.$Message.error('请填报完整!');
					}
				})
			},
			padLeftZero(str) {
				return ('00' + str).substr(str.length);
			},

		},


	}
</script>

<style lang='css' scoped>
	@import '../../../../index.css';
</style>
